package com.main.by.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.main.by.dao.CateDao;
import com.main.by.dao.GeneralDao;
import com.main.by.entity.vo.AdminLoginVO;
import com.main.by.entity.vo.CateVO;

@Repository
public class CateDaoImpl implements CateDao{
	
	@Autowired
	private GeneralDao generalDao;

	@Override
	public List<CateVO> findAllCate() throws Exception {
		return (List<CateVO>) generalDao.findAllEntity(CateVO.class, "select * from renren_cate");
	}

	@Override
	public boolean addCate(String cateName) throws Exception {
		boolean successful = generalDao.saveEntity("insert into renren_cate(cateName) values(?)", 
				new Object[]{cateName});
		return successful;
	}
	
	@Override
	public CateVO findCateById(int cateId) throws Exception {
		return generalDao.getEntity(CateVO.class,new Object[]{cateId});
	}
	
	@Override
	public boolean updateCateById(CateVO cateInfo) throws Exception {
		boolean successful = generalDao.updateEntity("update renren_cate set cateName=? where cateId=?", 
				new Object[]{cateInfo.getCateName(),cateInfo.getCateId()});
		return successful;
	}
	
	@Override
	public boolean deleteCateById(int cateId) throws Exception {
		return generalDao.updateEntity("delete from renren_cate where cateId=? ",new Object[]{cateId});
	}
}
